//
//  ViewController.m
//  TrapDemo
//
//  Created by zkingsoft on 16/2/26.
//  Copyright (c) 2016年 zkingsoft. All rights reserved.
//

#import "ViewController.h"
#import "UINavigationItem+CustomBarButtonItem.h"
#import "TravelViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIImageView   *contentLineImageView;// 导航栏视图

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _contentLineImageView.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    _contentLineImageView.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"游记";
    
    _contentLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:37/255.0 green:195/255.0 blue:149/255.0 alpha:1.0f];
    //这句话 要写上。 默认是YES可能你得到的颜色与实际的不匹配。  默认为YES 说明是有透明度的。   如果不设置颜色表示是透明的
    self.navigationController.navigationBar.translucent = NO;
    
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"TRAVEL VOTES" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [button makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(0);
        make.right.equalTo(self.view).with.offset(0);
        make.centerY.equalTo(self.view.centerY);
        make.height.equalTo(40);
    }];
}

- (void)buttonClicked:(UIButton *)sender{
    TravelViewController *travelVC = [[TravelViewController alloc] init];
    
    [self.navigationController pushViewController:travelVC animated:YES];
}


#pragma mark - 找到导航栏的视图
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
